<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <%-- 页头 --%>
    <%@include file="../common/head.jsp" %>
</head>
<body>
<div class="wrapper">

    <%-- 导航 --%>
    <%@include file="manage-header.jsp" %>

    <%-- 侧边栏 --%>
    <%@include file="manage-sidebar.jsp" %>

    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="card-title">文章管理</div>
                            </div>
                            <div class="card-body">
                                <c:if test="${empty articleCategoryVoList}">
                                    <div class="alert alert-success">
                                        <h3>没有数据</h3>
                                        <button class="btn btn-default" onclick="window.location.href='/manage/article/category/list'">点击，返回分类</button>
                                    </div>
                                </c:if>
                                <c:if test="${!empty articleCategoryVoList}">
                                    <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <thead>
                                            <tr>
                                                <th>文章编号</th>
                                                <th>文章分类</th>
                                                <th>文章标题</th>
                                                <th>文章介绍</th>
                                                <th>文章图标</th>
                                                <th>文章状态</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <c:forEach items="${articleCategoryVoList}" var="vo">
                                                <tr>
                                                    <th>${vo.article.articleId}</th>
                                                    <td>${vo.articleCategory.acTitle}</td>
                                                    <td>${vo.article.articleTitle}</td>
                                                    <td>${vo.article.articleIntroduce}</td>
                                                    <td><i class="la ${vo.article.articleIcon}"></i></td>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${vo.article.articleState == 0}">
                                                                <span class="badge badge-default">已发布</span>
                                                            </c:when>
                                                            <c:when test="${vo.article.articleState == 1}">
                                                                <span class="badge badge-danger">存稿</span>
                                                            </c:when>
                                                        </c:choose>
                                                    </td>
                                                    <td>
                                                        <button class="btn btn-xs btn-info"
                                                                onclick="window.location.href='/article/detail/${vo.article.articleId}'">
                                                            查 看
                                                        </button>
                                                        <button class="btn btn-xs btn-success"
                                                                onclick="window.location.href='/manage/article/update/${vo.article.articleId}'">
                                                            更 新
                                                        </button>
                                                        <button class="btn btn-xs btn-danger" onclick="deleteArticle(${vo.article.articleId})">删 除</button>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                            </tbody>
                                        </table>
                                    </div>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <%-- 页脚 --%>
    <%@include file="../common/footer.jsp" %>

</div>
</body>

<%-- js --%>
<%@include file="../common/script.jsp" %>

<script>
    function deleteArticle(id) {
        if (confirm("警告：将永久删除该数据")) {
            $.ajax({
                type: "GET",
                url: "/manage/article/delete/" + id,
                dataType: "json",
                success: function (data) {
                    if (data.status == 200) {
                        alert(data.message);
                        window.location.reload();
                    }
                },
                error: function () {
                    alert("Ajax 请求错误");
                }
            });
        }
    }
</script>
</html>